package com.zzxy.mybatis12.entity.text;

import com.zzxy.mybatis12.entity.User;
import com.zzxy.mybatis12.entity.entity.Order;
import com.zzxy.mybatis12.entity.mapper.OrderMapper;
import com.zzxy.mybatis12.entity.mapper.UserMapper;
import com.zzxy.mybatis12.entity.vo.QueryVO;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Text {
    @org.junit.Test
    public void test() throws IOException{
        is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory ssf = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = ssf.openSession();
        User user = sqlSession.selectOne("findUserById", 1);
        System.out.println(user);
    }
    @After
    public void after() { sqlSession.close(); }

    @org.junit.Test
    public void test3(){
        UserMapper mapper = sqlSession.getMapper.class);
        User user = mapper.findUserById(1);
        System.out.println(user);

        QueryVO vo = new QueryVO();
        User user = new User();
        user.setId(1);
        Order order = new Order();
        order.setNumber("1000010");

        vo.setOrder(user);
        vo.setOrder(order);

        List<User> users = mapper.findUserByVo(vo);
        for (User user1 : users) {
            System.out.println(user1);
        }
        /*HashMap<String,String> map = new HashMap<>();
        map.put("username","张三丰");
        map.put("address","河南郑州");
        User userByMap = mapper.findUserByMap(map);
        System.out.println(userByMap);*/

        @org.junit.Test
                public void test6(){
            UserMapper mapper = sqlSession.getMapper(UserMapper.class);
            QueryVO vo = new QueryVO();
            ArrayList<Integer> ids = new ArrayList<>();
            ids.add(1);
            ids.add(3);
            ids.add(5);
            ids.add(7);
            ids.add(10);

            List<User> users = mapper.findUserByList(ids);
            vo.setIds(ids);
            List<User> users = mapper.findUserById(vo);
            for (user user :users) {
                System.out.println(user);
            }
        }
    }

    @org.junit.Text
    public void text7(){
        OrderMapper mapper = sqlSession.getMapper(OrderMapper.class);
        Order order = mapper.findDrderBy121(1);
        System.out.println(order);
    }
}
